package com.linser.gistools.common.datastore.model;

import org.opengis.feature.type.AttributeDescriptor;

/**
 * @author: linser
 * @Desc:字段类
 * @create: 2024-02-02 20:36
 **/
public class FieldModel {
    String fieldName;
    String fieldType;
    Class fieldTypeBinding;

    public FieldModel() {
    }

    public String getFieldName() {
        return this.fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldType() {
        return this.fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public Class getFieldTypeBinding() {
        return this.fieldTypeBinding;
    }

    public void setFieldTypeBinding(Class fieldTypeBinding) {
        this.fieldTypeBinding = fieldTypeBinding;
    }

    public static FieldModel getFromAttributeDescriptoe(AttributeDescriptor attributeDescriptor) {
        FieldModel fieldModel = new FieldModel();

        try {
            fieldModel.setFieldName(attributeDescriptor.getLocalName());
            fieldModel.setFieldType(attributeDescriptor.getType().getBinding().getSimpleName());
            fieldModel.setFieldTypeBinding(attributeDescriptor.getType().getBinding());
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        return fieldModel;
    }

    public String toString() {
        return this.getFieldName();
    }

    public boolean equals(Object obj) {
        boolean res = false;
        if (obj instanceof FieldModel && ((FieldModel)obj).getFieldName().equalsIgnoreCase(this.getFieldName()) && (((FieldModel)obj).getFieldTypeBinding().equals(this.getFieldTypeBinding()) || ((FieldModel)obj).getFieldTypeBinding().isAssignableFrom(this.getFieldTypeBinding()) || this.getFieldTypeBinding().isAssignableFrom(((FieldModel)obj).getFieldTypeBinding()))) {
            res = true;
        }

        return res;
    }
}